/*
*  SkyDefaultOpenALContext.h
*  
*
*  Created by Alexander Trutchenko on 11/02/12.
*  Copyright 2012 Free Team. All rights reserved.
*
*/

#ifndef __Sky_DefaultOpenALContext_h__
#define __Sky_DefaultOpenALContext_h__

#include "SkySoundEngine.h"

#include "SkyOpenALContext.h"
#include "SkySSTag.h"

namespace sky {

#define SKY_MAX_SOUND_SOURCE_COUNT 1000

////////////////////////////////////////////////////////
//
/** SkySSTagDefault
*  
*/
////////////////////////////////////////////////////////

class SkySSTagDefault: public SkySSTag
{
public:
	float _realGain;

public:
	SkySSTagDefault(float realGain = 1.f): _realGain(realGain) {;}
	virtual ~SkySSTagDefault() {;}
};

////////////////////////////////////////////////////////
//
/** SkyDefaultOpenALContext
*  
*/
///////////////////////////////////////////////////////

class SkySSTagDefault;
class SkySoundSourceStatic;
class SkySoundSourceStreaming;
class SkyOpenALBuffer;

class SkyDefaultOpenALContext : public SkyOpenALContext
{
	typedef std::multimap<int, SkySoundSourceStatic*>  SkyConnectedEffects; 
	typedef std::vector<SkySoundSourceStatic*>  SkyEffects; 
	typedef std::vector<SkySoundSourceStreaming*>  SkyBkMusic; 

private:
	SkyConnectedEffects _connectedEffects;
	unsigned int _maxSources;
	unsigned int _sourceCursor;

	float _effectsVolume;
	float _bkMusicVolume;

	SkyEffects _effects;
	SkyBkMusic _bkMusic;

private:
	static float s_effectsVolume;
//	static bool  s_effectsMute;
	static float s_bkMusicVolume;
//	static bool  s_bkMusicMute;

public:
	static void setEffectsVolume(float volume); // [0.f .. 1.f]
	static float effectsVolume() { return s_effectsVolume; }
//	static void setIsEffectsMute(bool isMuted); 
//	static bool isEffectsMute() { return s_effectsMute; }
	static void setBkMusicVolume(float volume); // [0.f .. 1.f]
	static float bkMusicVolume() { return s_bkMusicVolume; }
//	static void setIsBkMusicMute(bool isMuted); 
//	static bool isBkMusicMute() { return s_bkMusicMute; }

protected:
	virtual ~SkyDefaultOpenALContext();

public:
	SkyDefaultOpenALContext(unsigned int maxSources = SKY_MAX_SOUND_SOURCE_COUNT);

public:
// SkyOpenALContext functions
	virtual void setIsCurrent(bool isCurrent);

//work with sounds
		/** Returns sound ID and SKY_INVALID_ID if sound can't be played */
	int playEffect(const char* file, bool loop = false, float gain = 1.f, float pitch = 1.f);
	void stopEffect(int soundID);
	void stopAllEffects();
	void pauseAllEffects();
	void resumeAllEffects();

//work with streamed sounds - background music
		/** Returns sound ID and SKY_INVALID_ID if sound can't be played */
	int playBkMusic(const char* file, bool loop = false, float gain = 1.f, float pitch = 1.f);
	void stopBkMusic(int soundID);
	void stopBkMusic();
	void pauseBkMusic();
	void resumeBkMusic(); 

protected:
// SkyOpenALContext functions
	virtual void update(float dt);

// own functions
	int playStaticSound(SkySoundSourceStatic* source, SkyOpenALBuffer* fileBuffer, bool loop, float gain, float pitch);
	virtual SkySSTagDefault* createTag(float realGain);

}; // SkyDefaultOpenALContext


////////////////////////////////////////////////
//Helpers

#define FTL_DEFAULT_CONTEXT ((sky::SkyDefaultOpenALContext*)sky::SkySoundEngine::sharedEngine()->currentContext())


} // namespace sky

#endif //__Sky_DefaultOpenALContext_h__
